package com.zxy.supplier_system.server.xinyuan.controller

import com.zxy.supplier_system.server.utils.IntIdAndName
import com.zxy.supplier_system.server.xinyuan.service.XinyuanGoodsBrandService
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("xinyuan/goodsBrands")
class XinyuanGoodsBrandController(
    private val xinyuanGoodsBrandService: XinyuanGoodsBrandService
) {

    @GetMapping
    fun findAll(): List<IntIdAndName> {
        return xinyuanGoodsBrandService.findAll()
    }

    data class UpdateGoodsBrandRequest(val name: String)

    @PostMapping
    fun createGoodsBrand(@RequestBody request: UpdateGoodsBrandRequest){
        return this.xinyuanGoodsBrandService.createGoodsBrand(request)
    }

    @PutMapping("{id}")
    fun updateGoodsBrand(@PathVariable id: Int, @RequestBody request: UpdateGoodsBrandRequest) {
        return this.xinyuanGoodsBrandService.updateGoodsBrand(id,request)
    }

    @DeleteMapping("{id}")
    fun deleteGoodsBrand(@PathVariable id: Int) {
        return this.xinyuanGoodsBrandService.delete(id)
    }
}